﻿using ImageMagick;
using System.Drawing;

namespace Common.Core.ImageHelper
{
    public static class ImageSave
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sourceImage">原图</param>
        /// <param name="destFileName">目标图片地址</param>
        /// <param name="maxWidth">目标图片最大宽度</param>
        /// <param name="maxHeight">目标图片最大高度</param>
        /// <param name="quality">图片质量，用于压缩大小</param>
        public static void Fun1(Image sourceImage, string destFileName, int maxWidth, int maxHeight, int quality)
        {
            var destImage = new MagickImage(StreamByteImageConverter.ImageToBytes(sourceImage));
            if (maxWidth > 0 && maxHeight > 0)
            { 
                destImage.Resize(maxWidth,maxHeight);
            }

            destImage.Quality = quality;

            destImage.Write(destFileName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sourceImage">原图</param>
        /// <param name="destFileName">目标图片地址</param>
        /// <param name="quality">图片质量，用于压缩大小</param>
        public static void Fun2(Image sourceImage, string destFileName, int quality)
        {
            var destImage = new MagickImage(StreamByteImageConverter.ImageToBytes(sourceImage));
           
            destImage.Quality = quality;

            destImage.Write(destFileName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sourceImage">原图</param>
        /// <param name="destFileName">目标图片地址</param>
        public static void Fun3(Image sourceImage, string destFileName)
        {
            var destImage = new MagickImage(StreamByteImageConverter.ImageToBytes(sourceImage));

            destImage.Write(destFileName);
        }
    }
}
